import React, { Component } from 'react'
import Header from './header'
import Slider from './slider'
import List from './list'
import Add from './add'
import Time from '../../until/getTime'
import './index.css'

export default class home extends Component {
    state={
        defaultIndex:0,
        item:{},
        url:'/list/add'
    }

    setDefaultIndex = (index,item) =>{
      
        if(!item){
            // 点击添加
            item = {
                id:Time.getTimestamp(),
                type:'系统消息',
                title:'',
                ctx:'',
                createTime:Time.getTimestamp(),
                sendTime:null,
                status:'do'
            }
             // 此时为编辑
             this.setState({defaultIndex:index,item,url:'/list/add'})

        }else{
            // 此时为编辑
            this.setState({defaultIndex:index,item,url:'/list/edit'})
        }
    }

   


    render() {
        const {defaultIndex,item,url} = this.state
        return (
            <div>
                <Header />
                <Slider defaultIndex={defaultIndex} setDefaultIndex={this.setDefaultIndex}/>
               
                <div className="content">   
                {
                    defaultIndex? <Add url={url} item={item}  setDefaultIndex={this.setDefaultIndex}/>:<List setDefaultIndex={this.setDefaultIndex}/>
                }
                </div>
               
            </div>
        )
    }
}
